package com.example.arithmeticleetcode.leetcode.nov;


import java.util.*;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-11-10 09:13
 **/
public class Demo04 {

    public static void main(String[] args) {
        minDeletions("ceabaacb");
        minDeletions("abbccdd");
    }

    public static int minDeletions(String s) {
        char[] chars = s.toCharArray();
        Map<Character, Integer> map = new HashMap<>();
        for (char aChar : chars) {
            map.put(aChar, map.getOrDefault(aChar, 0) + 1);
        }
        HashSet<Integer> set = new HashSet<>(map.values());
        if (map.values().size() == set.size()) {
            return 0;
        }
        //开始排序
        Collection<Integer> values = map.values();
        List<Integer> list = new ArrayList<>();
        for (Integer value : values) {
            if (!set.remove(value)) {
                list.add(value);
            }
        }
        System.out.println(list);
        int count = 0;
        HashSet<Integer> set1 = new HashSet<>(map.values());
        for (Integer integer : list) {
            while (integer > 0) {
                if (set1.contains(integer)) {
                    integer--;
                    count++;
                } else {
                    set1.add(integer);
                    break;
                }
            }
        }
        System.out.println(count);
        System.out.println("--------------------------");
        return count;
    }
}
